﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace DimsMapper.Modules
{
    public static class GDI
    {
        [DllImport("user32.dll")]
        public static extern bool HideCaret(IntPtr hWnd);

        [DllImport("gdi32.dll")]
        public static extern int StretchDIBits(IntPtr hdc, int xDest, int yDest, int destWidth, int destHeight, 
            int xSrc, int ySrc, int srcWidth, int srcHeight, byte[] lpBits, [In] ref BITMAPINFO lpBitsInfo, uint iUsage, uint dwRop
        );

        public enum BitmapCompressionMode : uint
        {
           BI_RGB = 0,
           BI_RLE8 = 1,
           BI_RLE4 = 2,
           BI_BITFIELDS = 3,
           BI_JPEG = 4,
           BI_PNG = 5
        }

        [StructLayout(LayoutKind.Sequential, Pack=1)]
        public struct BITMAPINFOHEADER
        {
            public uint  biSize;
            public int   biWidth;
            public int   biHeight;
            public ushort   biPlanes;
            public ushort   biBitCount;
            public BitmapCompressionMode biCompression;
            public uint  biSizeImage;
            public int   biXPelsPerMeter;
            public int   biYPelsPerMeter;
            public uint  biClrUsed;
            public uint  biClrImportant;

            public void Init()
            {
                biSize = (uint)Marshal.SizeOf(this);
            }
        }

        [StructLayout(LayoutKind.Sequential, Pack=1)]
        public struct RGBQUAD
        {
            public byte rgbBlue;
            public byte rgbGreen;
            public byte rgbRed;
            public byte rgbReserved;
        }

        [StructLayoutAttribute(LayoutKind.Sequential, Pack=1)]
        public struct BITMAPINFO {
           /// <summary>
           /// A BITMAPINFOHEADER structure that contains information about the dimensions of color format.
           /// </summary>
           public BITMAPINFOHEADER bmiHeader;

           /// <summary>
           /// An array of RGBQUAD. The elements of the array that make up the color table.
           /// </summary>
           [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 256, ArraySubType = UnmanagedType.Struct)]
           public RGBQUAD[] bmiColors;
        }
    }
}
